package com.example.superoa.controller;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.SessionAttributes;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.superoa.model.pojos.Position;
import com.example.superoa.model.pojos.Staff;
import com.example.superoa.model.service.AttendService;
import com.example.superoa.model.service.BusinessService;
import com.example.superoa.model.service.LeaveService;
import com.example.superoa.model.service.MenuService;
import com.example.superoa.model.service.OvertimeService;
import com.example.superoa.model.service.PositionService;
import com.example.superoa.model.service.StaffService;
import com.example.superoa.model.vo.StaffVo;
import com.mysql.cj.Session;

@Controller
public class MenuController {
	@Autowired
	private StaffService staffservice;
	@Autowired
	private PositionService ps;
	
	@Autowired
	private MenuService m_ser;
	
	@Autowired
	private OvertimeService o_ser;
	
	@Autowired
	private BusinessService b_ser;
	
	@Autowired
	private AttendService a_ser;
	
	@Autowired
	private LeaveService l_ser;
	
	
	/*@RequestMapping("login")
	public void login(){
		
	}*/
	
	
	/*@RequestMapping("main-administrator")
	public void mainadministrator(Model model){
		//包括1级和1级下面的二级
				model.addAttribute("fun1", ps.allFunsByUser());
				//根据用户查询(需要登陆的时候查询并存储)
				model.addAttribute("funsId", ps.allFunsByUser(1));
	}*/
	@RequestMapping("main-employees")
	public void mainemployees(){
		
	}
	@RequestMapping("examination")
	public void examination(){
		
	}
	@RequestMapping("management")
	public void management(){
		
	}
	@RequestMapping("people")
	public void people(HttpSession session){
		session.setAttribute("arr", m_ser.selectOvertime(Integer.parseInt(session.getAttribute("sid").toString())));
		session.setAttribute("arry", m_ser.selectStaffShen(Integer.parseInt(session.getAttribute("sid").toString())));
	}
	@RequestMapping("shen-sousuo")
	@ResponseBody
	public Integer sousuo(Integer type,Date kai,Date jie,HttpSession session) {
		session.setAttribute("arr", m_ser.selectsousuo(m_ser.selectOvertime(Integer.parseInt(session.getAttribute("sid").toString())),type,kai,jie));
		session.setAttribute("arry", m_ser.selectsousuo(m_ser.selectStaffShen(Integer.parseInt(session.getAttribute("sid").toString())),type,kai,jie));
		return 1;
	}
	@RequestMapping("sousuo")
	public String sou(HttpSession session,Model model){
		model.addAttribute("shenqing", session.getAttribute("arry"));
		model.addAttribute("shenpi", session.getAttribute("arr"));
		return "sousuo";
	}
	//审批查看
	@RequestMapping("people-cha")
	public String demo18(Integer type,Integer shen,Integer id,Model model,HttpSession session) {
		JSONObject o=m_ser.selectShenpi(shen,id);
		model.addAttribute("staff", o);
		session.setAttribute("pstaff", m_ser.selectStaff(o.getInteger("staff_id")));
		model.addAttribute("type", type);
		model.addAttribute("shen", shen);
		model.addAttribute("id", id);
		return "kq-overtime-cha";
	}
	//审批
	@RequestMapping("shen-pi")
	@ResponseBody
	public Integer tong(Integer id,Integer type,Integer shen,String str) {
		//出差
		if(type==1) {
			b_ser.shen(id, shen, str);
		//补卡	
		}else if(type==2) {
			a_ser.shen(id, shen, str);
		//加班
		}else if(type==3) {
			o_ser.shen(id, shen, str);
		//请假
		}else if(type==4) {
			l_ser.shen(id, shen, str);
			//讲师申请
		}else if(type==5) {
			m_ser.xiugaiteach(id, shen, str);
		}else if(type==6) {
			m_ser.xgsub(id, shen, str);
		}else if(type==7) {
			m_ser.xiugaiteach1(id, shen, str);
		}else if(type==8) {
			m_ser.rapply(id, shen, str);
		}
		return 1;
	}
	//驳回
	@RequestMapping("kq-overtime-shen")
	public void demo15(HttpSession session,Model model) {
		model.addAttribute("staff",m_ser.selectStaff(Integer.parseInt(session.getAttribute("sid").toString())) );
	}
	@RequestMapping("kq-attendance-shen")
	public void demo16(HttpSession session,Model model) {
		model.addAttribute("staff",m_ser.selectStaff(Integer.parseInt(session.getAttribute("sid").toString())) );
	}
	@RequestMapping("kq-business-shen")
	public void demo17(HttpSession session,Model model) {
		model.addAttribute("staff",m_ser.selectStaff(Integer.parseInt(session.getAttribute("sid").toString())) );
	}
	@RequestMapping("apply")
	public void demo18(HttpSession session,Model model) {
		model.addAttribute("staff",m_ser.selectStaff(Integer.parseInt(session.getAttribute("sid").toString())) );
	}
	@RequestMapping("train-sqteach")
	public void demo19(HttpSession session,Model model) {
		model.addAttribute("staff",m_ser.selectStaff(Integer.parseInt(session.getAttribute("sid").toString())) );
	}
	@RequestMapping("salary-shenqing")
	public void jiemian(Model model,int sub_id,HttpSession session) {
		model.addAttribute("staff",m_ser.selectStaff(Integer.parseInt(session.getAttribute("sid").toString())) );
		model.addAttribute("sub_id", sub_id);
	}
	@RequestMapping("train-shenqing")
	public void demo20(HttpSession session,Model model,int apply_id,int pxapproval_id) {
		model.addAttribute("staff",m_ser.selectStaff(Integer.parseInt(session.getAttribute("sid").toString())) );
		model.addAttribute("apply_id", apply_id);
		model.addAttribute("pxapproval_id", pxapproval_id);
	}
	/*@RequestMapping("train-train")
	public void demo20(HttpSession session,Model model,int course_id) {
		model.addAttribute("staff",m_ser.selectStaff(Integer.parseInt(session.getAttribute("sid").toString())) );
		model.addAttribute("course_id", course_id);
	}*/
	@RequestMapping("role-management")
	public void daohang(){
		
	}
	/*@RequestMapping("main-oa")
	public void main(Model model) {
		//包括1级和1级下面的二级
		model.addAttribute("fun1", ps.allFunsByUser());
		//根据用户查询(需要登陆的时候查询并存储)
		model.addAttribute("funsId", ps.allFunsByUser(1));
	}*/
}
